import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:thingskit/Pages/DeviceSetting/all_collapse/rf_collapse.dart';
import 'package:thingskit/components/collapse.dart';

import 'group_collapse.dart';
import 'light_collapse.dart';

class SubCollapseController extends GetxController {
  final isLightMode = false.obs;
  final isGroupConfig = false.obs;
  final isRFconfig = false.obs;

  void setDefault() {
    isLightMode.value = false;
    isGroupConfig.value = false;
    isRFconfig.value = false;
  }

  void setModeFromJson(Map<String, dynamic> json) {
    isLightMode.value = json['lightmode_setting'] == 1;
    isGroupConfig.value = json['group_setting'] == 1;
    isRFconfig.value = json['rf_setting'] == 1;
  }
}

class SubCollapse extends StatelessWidget {
  SubCollapse({super.key});

  final SubCollapseController controller = Get.put(SubCollapseController());

  @override
  Widget build(BuildContext context) {
    return Obx(() {
      return Collapse(
        showArrow: true,
        allowMultiple: true,
        panels: [
          CollapsePanel(
              title: '亮灯模式配置',
              content: LightCollapse(),
              isSelected: controller.isLightMode.value,
              onSelectedChanged: (value) {
                controller.isLightMode.value = value;
              }
          ),
          CollapsePanel(
              title: '组别配置(可跨组联动)',
              isSelected: controller.isGroupConfig.value,
              content: GroupCollapse(),
              onSelectedChanged: (value) {
                controller.isGroupConfig.value = value;
              }
          ),
          CollapsePanel(
              title: 'RF配置',
              content: RFCollapse(),
              isSelected: controller.isRFconfig.value,
              onSelectedChanged: (value) {
                controller.isRFconfig.value = value;
              }
          ),
        ],
      );
    });
  }

}